package com.niiwoo.civet.mobile.vo.response.loan.credit;

import com.niiwoo.civet.trade.dto.response.credit.CreditLoanGuaranteeProjectResponseDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;

/**
 * 信用借历史数据(数据迁移)-我的担保项目列表响应VO
 *
 * @author liming
 * @date 2017-12-14 16:50
 */
@Getter
@Setter
@ApiModel(value = "我的信用借担保项目")
public class CreditLoanGuaranteeProject implements Serializable{

    private static final long serialVersionUID = 1016953607258753591L;

    @ApiModelProperty(value = "项目ID")
    private Long projectId;

    @ApiModelProperty(value = "借款人用户ID")
    private String borrowerUserId;

    @ApiModelProperty(value = "借款人电话")
    private String borrowerMobile;

    @ApiModelProperty(value = "借款人用户名")
    private String borrowerUserName;

    @ApiModelProperty(value = "借款人头像")
    private String borrowerHeadImg;

    @ApiModelProperty(value = "借款人昵称")
    private String borrowerNickName;

    @ApiModelProperty(value = "借款人性别",notes = "1-男 2-女")
    private Byte borrowerSex;

    @ApiModelProperty(value = "借款用途/标题")
    private String title;

    @ApiModelProperty(value = "借款人城市/市")
    private String loanCity;

    @ApiModelProperty(value = "借款人城市/区")
    private String loanArea;

    @ApiModelProperty(value = "满标时间",notes = "时间格式:yyyy-MM-dd HH:mm")
    private String fullSuccessTime;

    @ApiModelProperty(value = "发布时间",notes = "时间格式:yyyy-MM-dd HH:mm")
    private String publishTime;

    @ApiModelProperty(value = "担保费率",notes = "保留4位小数")
    private BigDecimal guaranteeRate;

    @ApiModelProperty(value = "项目期限")
    private Integer deadline;

    @ApiModelProperty(value = "项目总期数")
    private Integer totalPeriods;

    @ApiModelProperty(value = "项目总金额",notes = "保留2位小数")
    private BigDecimal contractAmount;

    @ApiModelProperty(value = "标的状态 1-还款中(已满标) 2-逾期待垫付(已满标) 3-已结清(已满标) 4-流标(已发布)",notes = "1,2,3-代表项目满标,4-代表项目发布")
    private Byte viewStatus;

    @ApiModelProperty(value = "项目实际担保金额",notes = "保留2位小数")
    private BigDecimal realAmount;

    @ApiModelProperty(value = "项目预期担保收益",notes = "保留2位小数")
    private BigDecimal expectedReturn;

    @ApiModelProperty(value = "项目底部文案提示")
    private String tips;

    @ApiModelProperty(value = "查看合同地址")
    private String contractUrl;

    @ApiModelProperty(value = "担保记录查看地址")
    private String guaranteeRecordUrl;


    @Getter
    @AllArgsConstructor
    public enum ViewProjectStatus{
        REPAYMENT((byte)1,"还款中","还款中状态无法及时更新，请到期联系客服查询","还款中状态无法及时更新，请到期联系客服查询，借款人还款后担保本金和收益会发放到银行卡。"),
        OVERDUE_REPAYMENT((byte)2,"逾期待垫付","借款人还款已逾期，请尽快联系客服进行垫付","借款人还款已逾期，请尽快联系客服进行垫付。"),
        FINISH((byte)3, "已结清","",""),
        MISCARRY((byte)4, "流标","","");

        private byte code;
        private String desc;
        private String tips;//担保项目列表提示语
        private String projectDetailTips;//担保项目详情提示语
    }

    public static CreditLoanGuaranteeProject copyPropertiesFromDTO2VO(CreditLoanGuaranteeProjectResponseDTO dto){
        Assert.notNull(dto,"copy object properties of CreditLoanGuaranteeProjectResponseDTO to CreditLoanGuaranteeProject error,source object is null.");
        CreditLoanGuaranteeProject project = new CreditLoanGuaranteeProject();
        project.setProjectId(dto.getProjectId());
        project.setBorrowerUserId(dto.getBorrowUserId());
        project.setBorrowerMobile(dto.getBorrowMobile());
        project.setBorrowerUserName(dto.getBorrowUserName());
        project.setBorrowerHeadImg(dto.getBorrowHeadImg());
        project.setBorrowerNickName(dto.getBorrowNickName());
        project.setBorrowerSex(dto.getBorrowSex());
        project.setTitle(dto.getTitle());
        project.setLoanCity(dto.getLoanCity());
        project.setLoanArea(dto.getLoanArea());
        project.setFullSuccessTime(Objects.isNull(dto.getFullSuccessTime()) ?
                "" : DateFormatUtils.format(dto.getFullSuccessTime(), "yyyy-MM-dd HH:mm"));
        project.setPublishTime(Objects.isNull(dto.getPublishTime()) ?
                "" : DateFormatUtils.format(dto.getPublishTime(),"yyyy-MM-dd HH:mm"));
        project.setGuaranteeRate(dto.getGuaranteeRate().setScale(4));
        project.setDeadline(dto.getDeadline());
        project.setTotalPeriods(dto.getTotalPeriods());
        project.setContractAmount(dto.getContractAmount().setScale(2));
        project.setRealAmount(dto.getRealAmount().setScale(2));
        project.setExpectedReturn(dto.getExpectedReturn().setScale(2));
        project.setContractUrl(dto.getContractUrl());
        return project;

    }
}

